<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Página para probar ajax</title>
</head>
<script src="/app/public/js/BSajax.js">&nbsp;</script>
<script>
function clearCombo(cmbCombo) {
	var i=0;
	for(i=cmbCombo.length; i>= 0; i-=1 ){
		cmbCombo.remove(i);
	}
}
	
function loadAjax(){
	loadTreeValue();
	loadTreeDetail();
	loadBank();
}

function loadTreeValue(){
	var httpAjax = getHttpRequest();
		
	httpAjax.onreadystatechange=function() {
		if(httpAjax.readyState==4) {
			clearCombo(document.getElementById('TreeValue'));
		  	var treeValue = httpAjax.responseXML;
		  	var root = getFirstElement(treeValue);
	  	
		  	var response = root.getElementsByTagName("Response")[0];
		  	var fields = response.getElementsByTagName("Fields")[0];
		  	var treeValue = fields.getElementsByTagName("GetTreeValue")[0];
		  	var records = treeValue.getElementsByTagName("Record");
	  	
		  	var len = records.length;
		  	var code = null;
		  	var desc = null;
		  	var combo = document.getElementById("TreeValue");
		  	for(var i = 0;i<len;i++){
		  		code = getText(records[i].getElementsByTagName("cID")[0]);
		  		desc = getText(records[i].getElementsByTagName("cDetail")[0]);
		  		addOption(combo, code, desc);
		  	}
		}
	}
	httpAjax.open("GET","/app/bsas?bsServiceName=AF.GetTreeValue&r=" + Math.random(),true);
	httpAjax.send(null);
}

function loadTreeDetail(){
	var httpAjax = getHttpRequest();
		
	httpAjax.onreadystatechange=function() {
		if(httpAjax.readyState==4) {
			clearCombo(document.getElementById('TreeDetail'));
		  	var treeValue = httpAjax.responseXML;
		  	var root = getFirstElement(treeValue);
	  	
		  	var response = root.getElementsByTagName("Response")[0];
		  	var fields = response.getElementsByTagName("Fields")[0];
		  	var treeValue = fields.getElementsByTagName("GetTreeDetail")[0];
		  	var records = treeValue.getElementsByTagName("Record");
	  	
		  	var len = records.length;
		  	var code = null;
		  	var desc = null;
		  	var combo = document.getElementById("TreeDetail");
		  	for(var i = 0;i<len;i++){
		  		code = getText(records[i].getElementsByTagName("cID")[0]);
		  		desc = getText(records[i].getElementsByTagName("cDetail")[0]);
		  		addOption(combo, code, desc);
		  	}
		}
	}
	httpAjax.open("GET","/app/bsas?bsServiceName=AF.GetTreeDetail&r=" + Math.random(),true);
	httpAjax.send(null);
}


function loadBank(){
	var httpAjax = getHttpRequest();
		
	httpAjax.onreadystatechange=function() {
		if(httpAjax.readyState==4) {
			clearCombo(document.getElementById('Bank'));
		  	var treeValue = httpAjax.responseXML;
		  	var root = getFirstElement(treeValue);
	  	
		  	var response = root.getElementsByTagName("Response")[0];
		  	var fields = response.getElementsByTagName("Fields")[0];
		  	var treeValue = fields.getElementsByTagName("GetBank")[0];
		  	var records = treeValue.getElementsByTagName("Record");
	  	
		  	var len = records.length;
		  	var code = null;
		  	var desc = null;
		  	var combo = document.getElementById("Bank");
		  	for(var i = 0;i<len;i++){
		  		code = getText(records[i].getElementsByTagName("cID")[0]);
		  		desc = getText(records[i].getElementsByTagName("cName")[0]);
		  		addOption(combo, code, desc);
		  	}
		}
	}
	httpAjax.open("GET","/app/bsas?bsServiceName=AF.GetBank&r=" + Math.random(),true);
	httpAjax.send(null);
}

</script>

<body>

<input type="button" value="Carga Combos Ajax" onclick="javascript:loadAjax()">

<select id="TreeValue"/>
<select id="Bank"/>
<select id="TreeDetail"/>

</body>
</html>